window.onload = function(){
    let startX = 0;  //手指接触屏幕时的X坐标
    let endX = 0;   //手指在屏幕上滑动时的X坐标
    let scrollBarLeft = 0;
    let scrollBox = document.getElementById('scrollBox');
    let scrollBar = document.getElementById('scrollBar');

    //滚动条向左滚动的极限位置
    let stop = scrollBox.offsetWidth-scrollBar.offsetWidth;

    //touchStrat
    scrollBox.addEventListener('touchstart',function(event){
        let touch = event.targetTouches[0];
        startX = touch.pageX;
        scrollBarLeft = scrollBar.offsetLeft;
    },false);

    //touchMove
    scrollBox.addEventListener('touchmove',function(event){
        let touch = event.targetTouches[0];
        endX = touch.pageX;
        let len = (endX - startX) + scrollBarLeft;
        if(len>=0){
            len=0;
        }
        if(len <= stop)
        {
            len=stop;
        }
        scrollBar.style.left = len + 'px';
    },false);
}  